function dreamSlave(dreamPar)
global masterRank; global DIE_TAG; global WORK_TAG;
% copy all the files

[status statusInfo] = MPI_Probe(masterRank, MPI_ANY_TAG, MPI_COMM_WORLD);
if status ~= MPI_SUCCESS 
    error(strcat('Error receiving data from the master '));
end

if statusInfo.tag == DIE_TAG
    return;
end;

[status receivedNumel] = MPI_Get_elements(statusInfo,[]);

if status ~= MPI_SUCCESS 
    error(strcat('Error receiving data from the master '));
end

receivedPackage = zeros([1,receivedNumel]);


MPI_Recv(receivedPackage, masterRank, WORK_TAG, MPI_COMM_WORLD);

reshapedPackage = reshape(receivedPackage,receivedNumel/size(dreamPar.parCols,2),size(dreamPar.parCols,2));

results = calcObjectiveScore(dreamPar, reshapedPackage);
results = reshape(results, 1, 2*size(results,1));

%disp(['Size:',num2str(size(results))]);
%disp(results);

MPI_Send(results,masterRank,WORK_TAG,MPI_COMM_WORLD);


terminate = 0;
while ~terminate
    [status statusInfo] = MPI_Probe(masterRank, MPI_ANY_TAG, MPI_COMM_WORLD);
    if status ~= MPI_SUCCESS 
        error(strcat('Error receiving data from the master '));
    end

    if statusInfo.tag == WORK_TAG
        [status receivedNumel] = MPI_Get_elements(statusInfo,[]);

        if status ~= MPI_SUCCESS 
            error(strcat('Error receiving data from the master '));
        end
        [status receivedNumel] = MPI_Get_elements(statusInfo,[]);

        if status ~= MPI_SUCCESS 
            error(strcat('Error receiving data from the master '));
        end

        receivedPackage = zeros([1,receivedNumel]);

        MPI_Recv(receivedPackage, masterRank, WORK_TAG, MPI_COMM_WORLD);

        reshapedPackage = reshape(receivedPackage,receivedNumel/size(dreamPar.parCols,2),size(dreamPar.parCols,2));
        
        results = calcObjectiveScore(dreamPar, reshapedPackage);

        MPI_Send(results,masterRank,WORK_TAG,MPI_COMM_WORLD);

    else
        terminate = 1;
    end;
    

end;